﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;

namespace BarManager.Core.Entity
{
    [DataContract]
    public class Promocion    
    {   
        [Required(ErrorMessage="Campo Promoción es obligatorio")]
        [DataMember]
        public int Id { get; set; }

        [Required]
        [DataType(DataType.MultilineText)]
        [StringLength(150)]
        [DataMember]
        public string Descripcion { get; set; }

        [Required]
        [DataType(DataType.Time)]
        [Display(Name = "Hora de Inicio")]
        [DataMember]
        public DateTime HoraInicio { get; set; }

        [Required]
        [DataType(DataType.Time)]
        [Display(Name = "Hora de Fin")]
        [DataMember]
        public DateTime HoraFin { get; set; }
              
        [DataMember]
        public bool Lunes { get; set; }
               
        [DataMember]
        public bool Martes { get; set; }

        [DataMember]
        public bool Miercoles { get; set; }

        [DataMember]
        public bool Jueves { get; set; }

        [DataMember]
        public bool Viernes { get; set; }

        [DataMember]
        public bool Sabado { get; set; }

        [DataMember]
        public bool Domingo { get; set; }

        [Required]
        [RegularExpression(@"^([0-9]*\,?[0-9]+|[0-9]+\,?[0-9]*)?$",
            ErrorMessage = "Descuento en Pesos invalido (0,00)")]
        [DataType(DataType.Currency)]
        [Display(Name = "Descunto en Pesos")]
        [DataMember]
        public decimal? DescuentoPesos { get; set; }

        [DataType(DataType.Currency)]
        [DataMember]
        public decimal Total
        {
            get
            {
                return (PromocionDetalleList != null && PromocionDetalleList.Count > 0) ? PromocionDetalleList.Sum(x => x.SubTotal) - DescuentoPesos.Value : 0;
            }
        }

        [DataMember]
        public virtual ICollection<PromocionDetalle> PromocionDetalleList { get; set; }

        public Promocion()
        {
            PromocionDetalleList = new List<PromocionDetalle>();
        }
    }
}
